import os
from glob import glob
import os.path as osp
from calculate_excel import calculate_excel
import time
from helper import *


def search(file_name, file_type):
    count = 0
    files = os.listdir(DATA_DIR)
    if file_name is None or file_name == '':
        print('文件名缺失')
        return 0
    if file_type == '':
        for file in files:
            if file_name in file:
                print(f'找到文件：{file}')
                file_path = osp.join(DATA_DIR, file)
                calculate_excel(file_path)
                count = count + 1
    else:
        for file in files:
            if file_name in file and file.endswith(file_type):
                print(f'找到文件：{file}')
                file_path = osp.join(DATA_DIR, file)
                calculate_excel(file_path)
                count = count + 1
    if count == 0:
        print(f'没找到文件名中含有’{file_name}’的文件！')
    return count


start = time.time()
if __name__ == '__main__':
    result = calculate_excel(r'D:\PycharmProjects\test4_2\data\6_课程目标达成情况评价报告-2017级软工.xls')
    # query_name = input('请输入文件名：')
    # query_type = input('请输入文件类型：')
    # count = search(file_name=query_name, file_type=query_type)
    # print(f'共找到{count}个文件')
    # file_paths = glob(osp.join(DATA_DIR, '*.xls'))
    # for file_path in file_paths:
    #     analyse_report_excel(file_path)
end = time.time()
print('\n运行时间{}s'.format(round(end - start, 2)))
